//
// Created by zhou on 2021/11/1.
//
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        int row=obstacleGrid.size();
        int col=obstacleGrid[0].size();
        int dp[row][col];
        if(obstacleGrid[0][0]==0)dp[0][0]=1;
        else dp[0][0]=0;
        for(int i=1;i<row;i++){
            if(obstacleGrid[i][0]){
                dp[i][0]=0;
            }
            else {
                dp[i][0]=dp[i-1][0];
            }
        }
        for(int i=1;i<col;i++){
            if(obstacleGrid[0][i]){
                dp[0][i]=0;
            }
            else {
                dp[0][i]=dp[0][i-1];
            }
        }
        for(int i=1;i<row;i++){
            for(int j=1;j<col;j++){
                if(obstacleGrid[i][j]){
                    dp[i][j]=0;
                }
                else{
                    dp[i][j]=dp[i-1][j]+dp[i][j-1];
                }
            }
        }
        return dp[row-1][col-1];
    }
};
int main(){
    Solution solution;
    vector<vector<int>> m={
            {1,0}
    };
    cout<<solution.uniquePathsWithObstacles(m);
}

